﻿@model PagedList<ADZ_Pushmessage>
@{
    ViewBag.Title = "推送消息列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    PushMsgListQueryModel paramModel = new PushMsgListQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (PushMsgListQueryModel)ViewBag.paramModel;
    }
}
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("PushMsgList", "PushMsg")" method="get">
    <div class="form_query">
        <div>
            消息标题：
            <input type="text" name="MsgTitle" id="MsgTitle" class="abc input-default" placeholder="" value="@paramModel.MsgTitle">&nbsp;
        </div>
        <div>
            发布时间：
            <input type="text" name="CreateTime_beg" class="calendar calendar-time" id="CreateTime_beg" value="@paramModel.CreateTime_beg.ToString(1)"> - <input type="text" name="CreateTime_end" class="calendar calendar-time" id="CreateTime_end" value="@paramModel.CreateTime_end.ToString(1)">&nbsp;
        </div><div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div>
        <div>
            <button type="submit" class="btn btn-primary">查询</button>
            &nbsp;<button type="button" class="btn btn-success" id="additem" onclick="document.location='addPushMsg'">添加</button>
            &nbsp;<button type="button" class="btn btn-success" id="additem" onclick="toMorePushMsg()">批量推送</button>
        </div>
    </div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:40px"><input type="checkbox" name="chkall" id="chkall" />全选</th>
            <th>消息标题</th>
            <th>消息内容</th>
            <th>发布时间</th>
            <th>状态</th>
            <th>接收者</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>
                    <input type="checkbox" name="cbx_last" value="@m.ID" />@m.ID
                </td>
                <td>@m.MsgTitle</td>
                <td>@m.MsgText</td>
                <td>@m.CreateTime.ToString(1)</td>
                <td>
                    @switch (m.MsgStatus)
                    {
                        case 0:
                            @:<div class="gray">未推送</div>
                            break;
                        case 10:
                            @:<div class="green">已推送</div>
                            break;
                        case 20:
                            @:<div class="blue">已读</div>
                            break;
                    }
                </td>
                <td>
                    @switch (m.ReceiveType)
                    {
                        case 0:
                            @:<div class="gray">全体用户</div>
                            break;
                        case 1:
                            @:<div class="blue">部分用户</div>
                            break;
                    }
                </td>
                <td>
                    <a href="javascript:void(0);" onclick="deletePushMsg(@m.ID)">删除</a>
                    <a href="@Url.Action("addPushMsg","PushMsg",new {id=m.ID })">编辑</a>
                    @if (m.MsgStatus == 0)
                    {
                        <a href="javascript:void(0);" onclick="pushMsg(@m.ID)">APP推送</a>
                    }
                </td>
            </tr>
        }
    }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"]
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };
    reloadHandler = function ()
    {
        window.location.reload();
    }
    function deletePushMsg(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要删除该消息吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("DeletePushMsg", "PushMsg")";
                      parameter = { id: id };
                      $.post(url, parameter, function (result) {
                          ShowActionResultForAll(result, reloadHandler, reloadHandler);
                      });
                      this.close();
                  }
              },
                cancelButton

            ]
        });
    }

    function pushMsg(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将消息推送至APP吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("PushMsg", "PushMsg")";
                      parameter = { id: id };
                      $.post(url, parameter, function (result) {
                          ShowActionResultForAll(result, reloadHandler, reloadHandler);
                      });
                      this.close();
                  }
              },
                cancelButton

            ]
        });
    }


    function toMorePushMsg() {
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要推送的消息", 'warning');
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '确定要将选择的消息都推送至APP吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("ToMorePushMsg", "pushmsg")";
                      parameter = {
                        ids: ids
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
                cancelButton

            ]
        });
    }
</script>